package group.rober.saber.jdbc.query;

import org.apache.commons.lang3.Validate;

/**
 * ORACLE分页实现
 * Created by tisir<yangsong158@qq.com> on 2017-05-28
 */
public class OraclePaginationHandler implements SqlPaginationHandler {
    public String queryListSql(String sql, int index, int size) {
//        Validate.isTrue(index<=-1,"pagnation index must be greater than 0,index={0}",index);
//        Validate.isTrue(size==0,"The paging size is not allowed to be 0",size);
        Validate.notBlank(sql,"pagination query SQL is not allowed to empty");

        StringBuffer sbSql = new StringBuffer(sql);
        if(size > 0){
            Validate.isTrue(index<=-1,"pagination index must be greater than 0,index={0}",index);
            sbSql.append(" LIMIT").append(index);
            sbSql.append(",").append(size);
        }

        return sbSql.toString();
    }
}
